<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <!-- 搜索区域 -->
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="12">
            <a-form-item label="权限名称">
              <a-input placeholder="请输入权限名称" v-model="queryParam.roleName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="权限状态">
              <j-dict-select-tag placeholder="请选择权限状态" v-model="queryParam.status" dictCode="is_enable"/>
            </a-form-item>
          </a-col>
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="12" :sm="24">
              <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 21px">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator" style="margin: 5px 0 10px 2px">
      <a-button @click="handleAdd" type="primary" icon="plus">创建权限</a-button>
    </div>

    <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
      <i class="anticon anticon-info-circle ant-alert-icon">
      </i> 已选择 <a><b>{{ selectedRowKeys.length }}</b></a>项
      <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>

    <div style="margin-top: 15px">
      <a-table
        style="height:500px"
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="descriptionSlot" slot-scope="text, record">
          <j-ellipsis :value="text" :length="20"></j-ellipsis>
        </template>

        <template slot="statusSlot" slot-scope="text, record">
          <span :style="{color: text === 'Y' ? '#67c23a' : 'red'}">{{ record.status_dictText }}</span>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />

          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDelete_(record.id)">删除</a>
              </a-menu-item>
              <!-- 操作日志 -->
              <a-menu-item>
                <j-operate-log :id="record.id"></j-operate-log>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <role-modal ref="modalForm" @ok="modalFormOk"></role-modal>
  </a-card>
</template>
<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import RoleModal from './modules/RoleModal'

  export default {
    name: 'RoleUserList',
    mixins: [JeecgListMixin],
    components: {
      RoleModal,
    },
    data() {
      return {
        columns: [
          {
            title: '权限名称',
            align: 'center',
            dataIndex: 'roleName'
          },
          {
            title: '权限描述',
            align: 'center',
            dataIndex: 'description',
            scopedSlots: { customRender: 'descriptionSlot' },
          },
          {
            title: '权限状态',
            align: 'center',
            dataIndex: 'status',
            scopedSlots: { customRender: 'statusSlot' },
          },
          {
            title: '创建人',
            align: 'center',
            dataIndex: 'createBy'
          },
          {
            title: '创建时间',
            dataIndex: 'createTime',
            align:"center",
            sorter: true
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/sys/role/list',
          delete: '/sys/role/delete',
          exportXlsUrl: 'sys/role/exportXls',
          importExcelUrl: 'sys/role/importExcel'
        }
      }
    },
    methods: {
      handleDelete_: function(id) {
        const that = this
        that.$confirm({
          title:'角色删除',
          content: (h) => {
            return h('div', {
              domProps: {
                innerHTML: `<div>
                              <div style="color: red">删除角色后所有关联账号将失去角色</div>
                              <div>你还要继续吗？</div>
                            </div>`
              },
            }, []);
          },
          okText: '继 续',
          onOk() {
            that.handleDelete(id)
          },
          onCancel() {  },
        });
      }
    }
  }
</script>
<style scoped>
</style>